package com.juc.juc_project.other;

import sun.nio.fs.RegistryFileTypeDetector;

import java.util.concurrent.atomic.AtomicReference;

/**
 * Created by fangjicai on 2020/4/7.
 */
public class ConcurrentAtomic {

    public static AtomicReference<Integer> reference=new AtomicReference<>(0);

    public static void main(String[] args) {
        //比较期望值与实际值，如果相同，则进行更新操作
        reference.compareAndSet(1,9);
        System.out.println("one:"+ reference.get());//0
        reference.compareAndSet(0,10);
        System.out.println("tow:"+reference.get());//10
        reference.compareAndSet(8,18);
        System.out.println("throw:"+reference.get());//10
        reference.compareAndSet(10,50000);
        System.out.println("for:"+reference.get());//50000
    }
}
